package com.fastloan.mgt.application.base.util;

import com.fastloan.mgt.application.base.dao.ApplicationMapper;
import com.fastloan.mgt.processcontrol.base.util.BeanFactoryUtil;
import com.fastloan.mgt.product.basics.dao.ProductMapper;
import com.fastloan.mgt.product.basics.model.Product;
import com.fastloan.mgt.product.basics.service.ProductService;
import com.fastloan.safe.core.util.ManagerKit;
import com.fastloan.safe.mgt.org.model.CmuOrg;
import com.fastloan.safe.mgt.org.service.CmuOrgService;

import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;

/**
 * @author yanwe
 * createTime 2017-11-2017/11/10 15:53
 */
public class CodeUtil {

    private static ApplicationMapper applicationMapper = BeanFactoryUtil.getBean(ApplicationMapper.class);

    private static ProductService productService = BeanFactoryUtil.getBean(ProductService.class);

    private static CmuOrgService orgService = BeanFactoryUtil.getBean(CmuOrgService.class);

    private static NumberFormat applicationFormat = new DecimalFormat("00000000000");


    public static synchronized String getApplicationCode() {
        return applicationFormat.format(applicationMapper.selectSequence());
    }

    public static synchronized String getProductCode(String orgId) {
        CmuOrg cmuOrg = orgService.selectByPrimaryKey(orgId);
        return cmuOrg.getOrgCode().substring(6) + "00000" + productService.selectSequence(orgId);
    }

    public static boolean noneValueList(List list) {
        if (list == null || list.size() == 0) {
            return true;
        }
        return false;
    }

}
